package com.hyfrogx.modules.manage.controller;

import cn.hutool.core.bean.BeanUtil;
import com.hyfrogx.common.utils.QueryExt;
import com.hyfrogx.common.utils.R;
import com.hyfrogx.common.validator.ValidatorUtils;
import com.hyfrogx.modules.manage.entity.video.HyVideoTypeEntity;
import com.hyfrogx.modules.manage.form.video.HyVideoTypeAddForm;
import com.hyfrogx.modules.manage.form.video.HyVideoTypeUpdateForm;
import com.hyfrogx.modules.manage.service.HyVideoTypeService;
import com.hyfrogx.modules.sys.controller.AbstractController;
import com.hyfrogx.modules.sys.entity.SysUserEntity;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Map;

/**
 * @ClassName HyVideoType
 * @Description TODO
 * @Author yangjun
 * @date 2019/12/5 16:19
 * @Version 1.0
 **/
@RestController
@RequestMapping("/manage/videoType")
@Api(value = "HyVideoTypeController", tags = {"后台-视频分类"})
public class HyVideoTypeController extends AbstractController {


    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    HyVideoTypeService hyVideoTypeService;


    /**
     * 获取点播上传管理-资源列表 过滤条件包含:点播视频名/点播状态/类别/话题/片型
     * @param params
     * @return
     */
    @PostMapping("/list")
    public R list(@RequestBody Map<String,Object> params) {
        return R.ok().put("data",hyVideoTypeService.getVideoTypeByConditions(new QueryExt(params)));
    }

    @PostMapping("/add")
    public R add(@RequestBody HyVideoTypeAddForm form) {

        ValidatorUtils.validateEntity(form);
        SysUserEntity user = getUser();
        HyVideoTypeEntity entity=new HyVideoTypeEntity();
        BeanUtil.copyProperties(form,entity);
        entity.setCreateDate(new Date());
        entity.setUid(user.getUserId());
        hyVideoTypeService.getBaseMapper().insert(entity);
        return R.ok();
    }

    @PostMapping("/update")
    public R add(@RequestBody HyVideoTypeUpdateForm form) {
        HyVideoTypeEntity entity=new HyVideoTypeEntity();
        BeanUtil.copyProperties(form,entity);
        entity.setUpdateDate(new Date());
        hyVideoTypeService.getBaseMapper().updateById(entity);
        return R.ok();
    }

    @PostMapping("/delete")
    public R add(@Validated Integer id) {
        if(id!=null){
            hyVideoTypeService.getBaseMapper().deleteById(id);
        }
        return R.ok();
    }

}
